Skip to content

Introduce Driver.executeQuery #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jan 26, 2023
Merged

Introduce Driver.executeQuery #1006

merged 39 commits into from
Jan 26, 2023

Conversation

bigmontz
Copy link
Contributor

@bigmontz bigmontz commented Oct 10, 2022

This method gives the user a simple interface and obvious place to start with the driver. Behind this method the full retry mechanism will be present. The results are eagerly returned and in memory. With this, we have removed the need for the user to have knowledge of transactions, routing control, streaming of results and cursor lifetimes, and any of the more complex concepts that are exposed when using the session object.

Running a simple write query:

const { keys, records, summary } = await driver.executeQuery(
    'CREATE (p:Person{ name: $name }) RETURN p', 
    { name: 'Person1'}
)

Running a read query:

const { keys, records, summary } = await driver.executeQuery(
   'MATCH (p:Person{ name: $name }) RETURN p',
   { name: 'Person1'},
   { routing: neo4j.routing.READERS}
)

Running a read query and transforming the result:

const person1 = await driver.executeQuery(
   'MATCH (p:Person{ name: $name }) RETURN p',
   { name: 'Person1'},
   {
     routing: neo4j.routing.READERS,
     resultTransformer: neo4j.resultTransformers.mappedResultTransformer({
       map(record) {
         return record.get('p')
       },
       collect(personArray) {
         return personArray[0]
       }
     })
   }
)

⚠️ This API is experimental

@bigmontz bigmontz marked this pull request as ready for review October 12, 2022 15:22
@bigmontz
Copy link
Contributor Author

Depends on: neo4j-drivers/testkit#531

Copy link
Member

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨


const output = driver?.executeQuery<string>(query, params, {
// @ts-expect-error
routing: 'GO FIGURE'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon ™️ (maybe) 🤣

@fbiville fbiville self-requested a review January 25, 2023 12:30
bigmontz and others added 21 commits January 25, 2023 15:53
This method gives the user a simple interface and obvious place to start with the driver. Behind this method the full retry mechanism will be present. The results are eagerly returned and in memory. With this, we have removed the need for the user to have knowledge of transactions, routing control, streaming of results and cursor lifetimes, and any of the more complex concepts that are exposed when using the session object.
During the tests was need to separte a `QueryExecutor` class for better test coverage.
Co-authored-by: Robsdedude <dev@rouvenbauer.de>
@bigmontz bigmontz merged commit d332448 into neo4j:5.0 Jan 26, 2023
@bigmontz bigmontz deleted the 5.x-executeQuery branch January 26, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants